package com.hk.housekeeping.order.controller.trade;

import com.hk.housekeeping.order.entity.OrderTrade;
import com.hk.housekeeping.order.service.TradeDetailServ;
import com.hk.housekeeping.order.service.impl.TradeDetailServImpl;
import com.hk.housekeeping.order.utils.ResponseCode;
import com.hk.housekeeping.order.utils.ResponseEntity;
import com.hk.housekeeping.order.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/trade/detail")
public class TradeDetailController extends HttpServlet {
    private TradeDetailServ tradeDetailServ = new TradeDetailServImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String sid = req.getParameter("sid");
        ResponseEntity<OrderTrade> entity = null;
        //调用业务逻辑
        try {
            entity = tradeDetailServ.getTradeContent(sid);
        } catch (SQLException throwables) {
            entity = ResponseEntity.error(ResponseCode.TRADE_DATA_GET_ERROR);
        }

        ResponseUtils.deliver(resp, entity);
    }
}
